package com.loan.utils;

import com.loan.exeception.AppExceptionCodeMsg;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.io.Serializable;


/**
 * 统一信息返回类
 * @author zc
 * @param <T>
 */
@Getter
@Setter
@ToString
public class ResponseResult<T> implements Serializable {

    private static final long serialVersionUID = 764353425429180118L;
    /**
     * 状态码
     */
    @ApiModelProperty("状态码")
    private int code;

    /**
     * 提示信息
     */
    @ApiModelProperty("提示信息")
    private String msg;

    /**
     * 结果集
     */
    @ApiModelProperty("返回数据")
    private T data;

    private ResponseResult(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
    private ResponseResult(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static <T> ResponseResult<T> success(T data){
        return new ResponseResult<>(200, "success", data);
    }
    public static <T> ResponseResult<T> success(String msg){
        return new ResponseResult<>(200,msg);
    }
    public static <T> ResponseResult<T> success(String msg,T data){
        return new ResponseResult<>(200,msg,data);
    }

    public static <T> ResponseResult<T> failed(AppExceptionCodeMsg appExceptionCodeMsg){
        return new ResponseResult<>(appExceptionCodeMsg.getCode(), appExceptionCodeMsg.getMsg(),null);
    }


    public static <T> ResponseResult<T> failed(int code,String msg){
        return new ResponseResult<>(code,msg,null);
    }
    public static <T> ResponseResult<T> failed(String msg){
        return new ResponseResult<>(999,msg,null);
    }


}
